package org.example;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.lang.reflect.Method;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
        int i = 0;
        int[] z;
        z = new int[]{1, 3, 5, 3};
        z[0] = 7;
        z = Arrays.copyOf(z, z.length + 1);

        z[z.length - 1] = z.length;
        int[] x = Arrays.copyOfRange(z, 0, z.length + 1);

        for (int a = 0; a < z.length; a++) {
            System.out.print(z[a] + ",");
        }
        System.out.println("\n" + z.length);
        for (int a = 0; a < x.length; a++) {
            System.out.print(x[a] + ",");
        }
        text();
        File file = new File("C:\\Users\\tedu\\IdeaProjects\\jsd\\java2411\\src\\main\\java\\org\\example\\demo.txt");
        System.out.println("5" + 2);
        int count = 0;
        for (i = 1; i <= 10; i++) {
            if (i == 5) {
                continue;
            }
            for (int j = 1; j <= 10; j++) {
                if (j == 5) {
                    break;
                }
                count++;
            }
        }
        System.out.println(count);

        String regx = "\\d{1,}";
        String str ="abc3abc44abc555abc";
        str = str.replaceAll(regx,"#");
        System.out.println(str);//看不懂

        Student s=new Student();
        System.out.println(s.name);

        File file1=new File("./text.txt");
        if (!file1.exists())
        {
            file1.createNewFile();
            System.out.println(111);
        }
        FileOutputStream fos1=new FileOutputStream("text.txt",true);
        String line="网上大学上大学分割线嘎嘎嘎行\n";
        byte[] date=line.getBytes(StandardCharsets.UTF_8);
        //fos1.write(date);
        System.out.println("写了？？");

        File file2=new File("./text.txt");
        File file3=new File("C:\\Users\\tedu\\IdeaProjects\\jsd\\java2411\\src\\main\\java\\org\\example\\Main.java");
        FileInputStream fis1=new FileInputStream(file3);
        byte[] dt=new byte[(int)file3.length()];
        fis1.read(dt);
        System.out.println(Arrays.toString(dt));
        String l=new String(dt,StandardCharsets.UTF_8);
        System.out.println(l);
        System.out.println("??");
        fis1.close();

//        if (file1.exists())
//        {
//            file1.delete();
//            System.out.println(222);
//        }
        File dir=new File("example");
        System.out.println(dir.exists());
        FileInputStream fis = new FileInputStream("123.png");
        FileOutputStream fos = new FileOutputStream("123_cp.png");

        int d;
        while((d= fis.read())!=-1){
            fos.write(d);
        }
        System.out.println("复制完毕");

        fis.close();
        fos.close();

        InputStream inputStream=new InputStream() {
            @Override
            public int read() throws IOException {
                Student ss=new Student();
                return 0;
            }
        };
//        OutputStream outputStream=new OutputStream() {
//            @Override
//            public void write(int b) throws IOException {
//                Student ss=new Student();
//            }
//        };
//
//        FileInputStream fileInputStream=new FileInputStream("");
//        FileOutputStream fileOutputStream=new FileOutputStream("");
//        ObjectInputStream objectInputStream=new ObjectInputStream(fileInputStream);

//        Thread t=Thread.currentThread();
        // 输出当前线程的名称
        System.out.println("当前线程的名称: " + Thread.currentThread().getName());

        // 输出当前线程的ID
        System.out.println("当前线程的ID: " + Thread.currentThread().getId());

        // 输出当前线程的状态（注意：这个状态可能会随着线程的执行而变化）
        System.out.println("当前线程的状态: " + Thread.currentThread().getState());

        Class cls=Class.forName("org.example.Person");


        Method[] methods=cls.getDeclaredMethods();//扫描所有方法
        Object obj=cls.newInstance();//实例化对象
       for (Method method:methods)//遍历所有方法
       {
           boolean isAutoclass=method.isAnnotationPresent(Autoclass.class);//判断是否包含注解
           System.out.println(method.getName()+" :  "+((isAutoclass)?"true":"false"));
           if (isAutoclass)
           {
               method.invoke(obj);//调用方法
               Autoclass ac=method.getAnnotation(Autoclass.class);
               System.out.println(ac.value());
           }
       }


    }





              public <T> T show(T t)
                {
                     return t;
                 }
              static class Person
              {
                       Person()
                       {
                         System.out.println("Person");
                       }
              }
                         static class Student extends Person
                        {
                            public String name = "zhangsan";
                            Student()
                            {
                                System.out.println("student");
                            }
                        }




                    static void text()
                    {
                        Collection collection=new ArrayList();
                        collection.add("sdad");
                        collection.add("777");
                        System.out.println(collection);
                        System.out.println(collection.size());
                        System.out.println(collection.isEmpty());

                        collection.clear();
                        System.out.println(collection);
                        System.out.println(collection.isEmpty());
                    }
                }

